<template>
  <div class="bgGray">
    <div class="container">
        <div class="nav2">
            <div>
                <img src="../../assets/img/热销媒体列表/切图/0.png"><span>领域:</span>
            </div>
            <ul>
                <li v-for="(item,index) in resultBefore" :key="index" @click="changeColor2(index)">
                    <img :src="imgSelect2(index)" alt=""><span :class="{red:index2==index,black:index2!=index}">{{item.data_value}}</span>
                </li>
            </ul>
            <div @click="zk"><img :src="src"><span>{{name}}</span></div>
        </div>
        <div class="nav3">
          <div>
              <img src="../../assets/img/热销媒体列表/切图/0.png"><span>排序:</span>
          </div>
          <ul>
              <li v-for="(item,index) in navList1" :key="index" @click="changeColor3(index)">
                  <img :src="item[0]"><span :class="{red:index3==index,black:index3!=index}">{{item[1]}}</span>
              </li>
          </ul>
          <div>
              <input type="text" v-model="input1" placeholder="请输入关键词进行搜索">
              <div>
                  <img src="../../assets/img/热销媒体列表/切图/6.png" alt="" @click="search">
              </div>
          </div>
        </div>
        <div class="content">
          <ul class="list">
              <li v-for="(item,index) in result3" :key="index" style="height:235px;" >
                  <ul class="add-border">
                      <li>
                          <img :src="item.logo" width="90px" height="90px">
                      </li>
                      <li>
                          <p>{{item.mediaName}}</p>
                          <p>简介：{{item.about}}</p>
                      </li>
                      <li>
                          <p>月活</p>
                          <p>{{numLen(item.monthToLive+"")}}</p>
                      </li>
                      <li>
                          <p>媒体领域</p>
                          <p>{{item.mediaSectorStr}}</p>
                      </li>
                      <li>
                          <p>售卖方式</p>
                          <p>{{item.sellingWay}}</p>
                      </li>
                      <li>
                          <p>参考价格</p>
                          <p>{{item.appPrice}}</p>
                      </li>
                      <li>
                          <div><button @click="addctrl(index)">{{ctrlName}}</button></div>
                          <div><button @click="$router.push({path:'/view2/shortVideoDetail',query:{id:item.id }})">查看详情</button></div>
                      </li>
                  </ul>
              </li>
          </ul>
          <el-pagination class="page"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :page-sizes="[10, 20, 50, 100]"
          :page-size="5"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total">
          </el-pagination>
        </div>
    </div>
  </div>
</template>
<script>
const img1 = require("../../assets/img/热销媒体列表/切图/1.png");
const img2 = require("../../assets/img/热销媒体列表/切图/2.png");
const img4 = require("../../assets/img/热销媒体列表/切图/4.png");
const img8 = require("../../assets/img/热销媒体列表/切图/8.png");
const img5 = require("../../assets/img/热销媒体列表/切图/5.png");
const img9 = require("../../assets/img/热销媒体列表/切图/9.png");
const img10 = require("../../assets/img/收藏夹/切图/4.png");
const img11 = require("../../assets/img/收藏夹/切图/5.png");
const img12 = require("../../assets/img/收藏夹/切图/6.png");
const img13 = require("../../assets/img/收藏夹/切图/7.png");
const img14 = require("../../assets/img/收藏夹/切图/8.png");
export default {
  data() {
    return {
      // 判断是否从APP矩阵进入的
      showMedia: true,
      navList1: [[img5, "综合", img9], [img5, "人气", img9]],
      index3: 0,
      input1: "",
      // 列表一需要显示默认进行勾选的。
      index1: 0,
      // 列表一需要显示默认进行勾选的。
      index2: 0,
      // 路由参数type，默认勾选
      type: "",
      // 查询结果2
      result2: "",
      // 查询结果3
      result3: "",
      // 展开显示数据
      resultBefore: "",
      // 默认勾选样式
      imgDef: img1,
      // 选中样式
      imgCli: img2,
      name: "点击展开",
      src: img8,
      key: 6,
      page: 1,
      limit: 10,
      order: "",
      sort: "ASC",
      orderList: ["03", "04"],
      smallIcon: "",
      // 分页总条数
      total: 0,
      ctrlName: "加入收藏夹"
    };
  },
  computed: {
    args() {
      return {
        type: this.type,
        page: this.page,
        limit: this.limit,
        dicCode: "003",
        dataKey: this.key,
        order: this.order,
        sort: this.sort
      };
    }
  },
  methods: {
    search() {
      this.$ajax
        .post(this.Ipurl + "popularMedia/search", {
          page: this.page,
          limit: this.limit,
          str: this.input1
        })
        .then(res => {
          if (res.data.returnCode == 1000) {
            this.total = res.data.dataInfo.total;
            this.result3 = res.data.dataInfo.records;
            this.typeData();
          } else {
            this.$message.error("没有查询到搜索信息");
          }
        });
    },
    changeColor3(index) {
      // img9为降序标识
      if (this.navList1[index][0] == img5) {
        this.navList1[index][0] = img9;
      } else {
        this.navList1[index][0] = img5;
      }
      this.index3 = index;
      if (this.navList1[index][0] == img9) {
        this.sort = "DESC";
      } else {
        this.sort = "ASC";
      }
      this.order = this.orderList[index];
      this.$ajax
        .post(this.Ipurl + "popularMedia/selectListByKey", this.args)
        .then(res => {
          this.total = res.data.dataInfo.total;
          this.result3 = res.data.dataInfo.records;
        });
    },
    // 图片样式控制
    imgSelect1(index) {
      if (index == this.index1) {
        return this.imgDef;
      } else {
        return this.imgCli;
      }
    },
    changeColor2(index) {
      this.index2 = index;
      this.key = this.result2[index]["data_key"];
      this.$ajax
        .post(this.Ipurl + "popularMedia/selectListByKey", this.args)
        .then(res => {
          this.total = res.data.dataInfo.total;
          this.result3 = res.data.dataInfo.records;
        });
    },
    imgSelect2(index) {
      if (index == this.index2) {
        return this.imgDef;
      } else {
        return this.imgCli;
      }
    },
    zk() {
      if (this.name == "点击展开") {
        this.name = "点击收起";
        this.src = img4;
        this.resultBefore = this.result2;
      } else {
        this.name = "点击展开";
        this.src = img8;
        this.resultBefore = this.result2.slice(0, 6);
      }
    },
    // 分页--条数
    handleSizeChange(val) {
      this.limit = val;
      this.$ajax
        .post(this.Ipurl + "popularMedia/selectListByKey", this.args)
        .then(res => {
          this.result3 = res.data.dataInfo.records;
        });
    },
    // 分页--页数
    handleCurrentChange(val) {
      this.page = val;
      this.$ajax
        .post(this.Ipurl + "popularMedia/selectListByKey", this.args)
        .then(res => {
          this.result3 = res.data.dataInfo.records;
        });
    },
    // 收藏夹
    addctrl(index) {
      if (this.ctrlName == "加入收藏夹") {
        // 是否登录，加入收藏夹
        if (window.sessionStorage.getItem("userInfo")) {
          if (this.ctrlName == "加入收藏夹") {
            this.$ajax
              .post(this.Ipurl + "favoriteInfo/save", {
                userId: JSON.parse(window.sessionStorage.getItem("userInfo"))
                  .userId,
                popularMediaId: this.result3[index].id,
                type: this.result3[index].type
              })
              .then(res => {
                if (res.data.returnCode == 1000) {
                  this.$message("添加成功");
                  this.ctrlNum++;
                  this.ctrlName = "已经加入";
                  //  alert(this.ctrlNum)
                } else {
                  this.$message.error("添加失败");
                }
              });
          } else {
            this.$message.error("不可以重复添加");
          }
        } else {
          this.$confirm("检测到您并没有登录", "warning", {
            confirmButtonText: "立即登录",
            cancelButtonText: "不了，谢谢",
            type: "warning"
          }).then(() => {
            this.$router.push("/login");
          });
        }
      }
    }
  },
  mounted() {
    if (this.$route.query.type) {
      this.type = this.$route.query.type;
      // 读取列表二
      this.$ajax
        .post(
          this.Ipurl + "sysdictionarydata/getValueListByCode" + "?dicCode=003"
        )
        .then(res => {
          this.result2 = res.data.dataInfo;
          // 显示前6个
          this.resultBefore = this.result2.slice(0, 6);
          // 读取默认内容数据
          this.$ajax
            .post(this.Ipurl + "popularMedia/selectListByKey", this.args)
            .then(res => {
              this.total = res.data.dataInfo.total;
              this.result3 = res.data.dataInfo.records;
            });
        });
    } else {
      // 不是从路由进行跳转
      this.$ajax
        .post(
          this.Ipurl + "sysdictionarydata/getValueListByCode" + "?dicCode=003"
        )
        .then(res => {
          this.result2 = res.data.dataInfo;
          this.key = this.result2[0]["data_key"];
          this.type = "app";
          // 显示前6个
          this.resultBefore = this.result2.slice(0, 6);
          // 读取默认内容数据
          this.$ajax
            .post(this.Ipurl + "popularMedia/selectListByKey", this.args)
            .then(res => {
              this.total = res.data.dataInfo.total;
              this.result3 = res.data.dataInfo.records;
              // console.log(this.result3);
            });
        });
    }
  }
};
</script>

<style scoped>
.bgGray {
  width: 100%;
  background: #f8f9fd;
  overflow: hidden;
}
.container {
  width: 1200px;
  margin: 0 auto;
  margin-top: 50px;
  overflow: hidden;
  background: #fff;
}
.nav2 > div {
  float: left;
  width: 150px;
  height: 60px;
  line-height: 60px;
  text-align: center;
}
.nav2 > div > span {
  margin-left: 20px;
  font-size: 16px;
  font-weight: bold;
}
.nav2 > ul {
  float: left;
  overflow: hidden;
  width: 1050px;
}
.nav2 > ul > li {
  float: left;
  width: 170px;
  height: 60px;
  line-height: 60px;
  font-size: 16px;
  cursor: pointer;
  overflow: hidden;
}
.nav2 > ul > li > span {
  margin-left: 10px;
}
.nav2 > ul > li > span.red {
  color: rgb(237, 64, 64);
}
.nav2 > ul > li > span.black {
  color: rgb(34, 34, 34);
}
.nav2 > div:nth-child(3) {
  width: 100%;
  text-align: center;
  height: 24px;
  line-height: 24px;
  background: rgb(237, 64, 64);
  cursor: pointer;
}
.nav2 > div:nth-child(3) > span {
  font-size: 16px;
  color: #fff;
  margin-left: 8px;
}
.nav2 > div:nth-child(3) > img {
  margin-top: -5px;
}
.content {
  width: 1200px;
  margin: 0 auto;
  margin-top: 20px;
  overflow: hidden;
}
.list {
  overflow: hidden;
}
.list > li > ul > li {
  float: left;
  height: 200px;
  margin-top: 20px;
  background: #fff;
}
.list > li > ul > li:nth-child(1) {
  width: 190px;
  text-align: center;
  line-height: 200px;
  position: relative;
}
.list > li > ul > li:nth-child(1) > img:nth-child(2) {
  /* 下侧小图 */
  position: absolute;
  top: 115px;
  right: 50px;
}
.list > li > ul > li:nth-child(2) {
  width: 285px;
}
.list > li > ul > li:nth-child(2) > p:nth-child(1) {
  font-size: 18px;
  font-weight: bold;
  margin-top: 76px;
}
.list > li > ul > li:nth-child(2) > p:nth-child(2) {
  font-size: 14px;
  font-weight: bold;
  margin-top: 20px;
  color: rgb(34, 34, 34);
}
.list > li > ul > li:nth-child(3),
.list > li > ul > li:nth-child(4),
.list > li > ul > li:nth-child(5),
.list > li > ul > li:nth-child(6),
.list > li > ul > li:nth-child(7) {
  width: 100px;
  height: 200px;
  text-align: center;
}
.list > li > ul > li > p:nth-child(1) {
  font-size: 14px;
  font-weight: bold;
  margin-top: 76px;
}
.list > li > ul > li > p:nth-child(2) {
  font-size: 16px;
  font-weight: bold;
  margin-top: 20px;
  color: rgb(237, 64, 64);
}
.list > li > ul > li:last-child {
  width: 200px;
}
.list > li > ul > li:last-child > div {
  text-align: center;
}
.list > li > ul > li:last-child > div:nth-child(2) > button {
  width: 100px;
  height: 30px;
  border: 1px solid rgb(34, 34, 34);
  border-radius: 15px;
  margin-top: 16px;
  font-size: 14px;
  font-weight: bold;
  background: #fff;
}
.list > li > ul > li:last-child > div:nth-child(1) > button {
  width: 100px;
  height: 30px;
  border-radius: 15px;
  margin-top: 20px;
  color: #fff;
  background: rgb(237, 64, 64);
  font-size: 14px;
  font-weight: bold;
}
.add-border{
  border-top:15px solid #f8f9fd;
 position: relative;
}
.page {
  margin-left: 250px;
}
.nav3 {
  width: 1200px;
  margin: 0 auto;
  margin-top: 20px;
  overflow: hidden;
  background: #fff;
}
.nav3 > div:nth-child(1) {
  float: left;
  width: 150px;
  height: 60px;
  line-height: 60px;
  text-align: center;
}
.nav3 > div:nth-child(1) > span {
  margin-left: 20px;
  font-size: 16px;
  font-weight: bold;
}
.nav3 > ul {
  float: left;
  overflow: hidden;
}
.nav3 > ul > li {
  float: left;
  width: 170px;
  height: 60px;
  line-height: 60px;
  font-size: 16px;
  cursor: pointer;
}
.nav3 > ul > li > span {
  margin-left: 10px;
}
.nav3 > ul > li > span.red {
  color: rgb(237, 64, 64);
}
.nav3 > ul > li > span.black {
  color: rgb(34, 34, 34);
}
.nav3 > div:nth-child(3) {
  float: right;
  position: relative;
}
.nav3 > div:nth-child(3) > input {
  width: 268px;
  height: 32px;
  border: 1px solid rgb(237, 64, 64);
  margin-top: 10px;
  margin-right: 50px;
  border-radius: 10px 0 0 10px;
  padding-left: 15px;
}
.nav3 > div:nth-child(3) > div {
  width: 32px;
  height: 32px;
  text-align: center;
  line-height: 32px;
  position: absolute;
  top: 10px;
  right: 18px;
  border-radius: 0 10px 10px 0;
  cursor: pointer;
  background: rgb(237, 64, 64);
}
</style>
